const Exercise = require('../models/Exercise');

const sampleExercises = [
  {
    title: "城市化对环境的影响",
    content: "Some people think that urbanization has brought more negative effects than positive effects to the environment. To what extent do you agree or disagree?",
    type: "Task2",
    difficulty: "Medium",
    timeLimit: 40,
    wordLimit: 250
  },
  {
    title: "科技对教育的影响",
    content: "Technology has revolutionized the way we learn and teach. Discuss the advantages and disadvantages of using technology in education.",
    type: "Task2",
    difficulty: "Easy",
    timeLimit: 40,
    wordLimit: 250
  },
  {
    title: "远程工作的利弊",
    content: "Working from home has become increasingly popular. What are the benefits and drawbacks of remote work for both employees and employers?",
    type: "Task2",
    difficulty: "Medium",
    timeLimit: 40,
    wordLimit: 250
  },
  {
    title: "社交媒体对青少年的影响",
    content: "Social media has a significant impact on teenagers' lives. Do you think the benefits outweigh the disadvantages?",
    type: "Task2",
    difficulty: "Hard",
    timeLimit: 40,
    wordLimit: 250
  },
  {
    title: "图表描述 - 能源消费",
    content: "The chart below shows the energy consumption in different sectors in a country from 1990 to 2010. Summarize the information by selecting and reporting the main features, and make comparisons where relevant.",
    type: "Task1",
    difficulty: "Medium",
    timeLimit: 20,
    wordLimit: 150
  },
  {
    title: "图表描述 - 人口变化",
    content: "The graph illustrates the population changes in three cities over a 50-year period. Summarize the information by selecting and reporting the main features, and make comparisons where relevant.",
    type: "Task1",
    difficulty: "Easy",
    timeLimit: 20,
    wordLimit: 150
  },
  {
    title: "环保责任",
    content: "Environmental protection is the responsibility of governments rather than individuals. To what extent do you agree or disagree?",
    type: "Task2",
    difficulty: "Hard",
    timeLimit: 40,
    wordLimit: 250
  },
  {
    title: "在线购物趋势",
    content: "Online shopping has become increasingly popular. What are the reasons for this trend and what are its effects on society?",
    type: "Task2",
    difficulty: "Medium",
    timeLimit: 40,
    wordLimit: 250
  }
];

async function seedExercises() {
  try {
    // 检查是否已有数据
    const existingCount = await Exercise.countDocuments();
    if (existingCount > 0) {
      console.log(`📚 数据库中已有 ${existingCount} 个题目，跳过数据初始化`);
      return;
    }

    // 插入示例数据
    await Exercise.insertMany(sampleExercises);
    console.log(`✅ 成功插入 ${sampleExercises.length} 个示例题目`);
  } catch (error) {
    console.error('❌ 初始化示例数据失败:', error);
  }
}

module.exports = { seedExercises };
